home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / win / pascal / ssavwin.exe / SSAVEWIN.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1993-04-29  |  10.7 KB  |  217 lines

  1. Unit SSaveWin;
  2.  
  3. {****************************************************************************
  4. *****************************************************************************
  5. *                                                                           *
  6. *  SsaveWin.pas:                                                            *
  7. *  Unit for Windows 3.1 Screen Savers. Exports the object type for the      *
  8. *  screen saver main window, TScSaverWin.                                   *
  9. *                                                                           *
  10. *  Compiler: BP 7.0                                                         *
  11. *                                                                           *
  12. *  See SSaveDem.pas.                                                        *
  13. *                                                                           *
  14. *****************************************************************************
  15. *                                                                           *
  16. *  Copyright ⌐ 1993 Manfred Keul [100031,12].                               *
  17. *                                                                           *
  18. *  Rev. 0.1   28.3.93   MK  IR                                              *
  19. *                                                                           *
  20. *****************************************************************************
  21. ****************************************************************************}
  22.  
  23. interface
  24.  
  25. uses Objects, OWindows, Wintypes, Winprocs, SsavePwd;
  26.  
  27. {****************************************************************************
  28. *                                                                           *
  29. *                        T S c S a v e r W i n                              *
  30. *                                                                           *
  31. *  Main window of a screen saver.                                           *
  32. *                                                                           *
  33. *  When the screen saver "strikes", an instance of this window type will    *
  34. *  cover the whole screen. When the next mouse or keyboard event occurs,    *
  35. *  the method Stop asks for the password (if one is enabled). If the user   *
  36. *  enters the correct password, a WM_CLOSE message is posted - which        *
  37. *  should end the life cycle of this window.                                *
  38. *                                                                           *
  39. *  Default attributes of this window class: No cursor, "Black_Brush" as     *
  40. *  background, (WS_POPUP or WS_VISIBLE)                                     *
  41. *                                                                           *
  42. *  The Application is expected to call DoTheShow within its IdleAction      *
  43. *  method. So, DoTheShow is the method to put any animation into.           *
  44. *                                                                           *
  45. ****************************************************************************}
  46.  
  47. type
  48.   PScSaverWin = ^TScSaverWin;
  49.   TScSaverWin = Object(TWindow)
  50.     constructor Init(aParent:PWindowsObject; aTitle:PChar);
  51.     function GetClassName: PChar; virtual;
  52.     procedure GetWindowClass (var aWndClass: TWndClass); virtual;
  53.     procedure WMActivate    (var Msg: TMessage);virtual wm_first+WM_ACTIVATE;
  54.     procedure WMMousemove   (var Msg: TMessage);virtual wm_first+WM_MOUSEMOVE;
  55.     procedure WMLbuttondown (var Msg: TMessage);virtual wm_first+WM_LBUTTONDOWN;
  56.     procedure WMRbuttondown (var Msg: TMessage);virtual wm_first+WM_RBUTTONDOWN;
  57.     procedure WMMbuttondown (var Msg: TMessage);virtual wm_first+WM_MBUTTONDOWN;
  58.     procedure WMSyskeydown  (var Msg: TMessage);virtual wm_first+WM_SYSKEYDOWN;
  59.     procedure WMKeydown     (var Msg: TMessage);virtual wm_first+WM_KEYDOWN;
  60.     procedure Stop (var Msg: TMessage); virtual;
  61.     procedure DoTheShow; virtual;
  62.   end;
  63.  
  64.  
  65. {****************************************************************************
  66. *                                                                           *
  67. *                         I m p l e m e n t a t i o n                       *
  68. *                                                                           *
  69. ****************************************************************************}
  70.  
  71. implementation
  72.  
  73. var  LastMouse: Tpoint;
  74.  
  75. {****************************************************************************
  76. *                                                                           *
  77. *        T S c S a v e r W i n . G e t C l a s s N a m e,                   *
  78. *                            - . G e t W i n d o w C l a s s,               *
  79. *                            - . I n i t                                    *
  80. *                                                                           *
  81. *  Register the window class and set the default attributes.                *
  82. *                                                                           *
  83. ****************************************************************************}
  84.  
  85. function TScSaverWin.GetClassName: PChar;
  86. begin
  87. GetClassName := 'BPScreenSaver';
  88. end;
  89.  
  90. procedure TScSaverWin.GetWindowClass (var aWndClass:TWndClass);
  91. begin
  92. inherited GetWindowClass (aWndClass);
  93. aWndClass.hCursor := 0 ;
  94. aWndClass.hbrBackground := GetStockObject (Black_Brush);
  95. end;
  96.  
  97. constructor TScSaverWin.Init (aParent: PWindowsObject; aTitle: PChar);
  98. begin
  99. inherited Init (aParent, aTitle);
  100. with Attr do
  101.     begin
  102.     Style := WS_POPUP or WS_VISIBLE;
  103.     X := 0;                                                 { let window....}
  104.     Y := 0;
  105.     W := GetSystemMetrics (SM_CXSCREEN);
  106.     H := GetSystemMetrics (SM_CYSCREEN);         {...cover the whole screen }
  107.     end;
  108. end;
  109.  
  110. {****************************************************************************
  111. *                                                                           *
  112. *              T S c S a v e r W i n . W M A c t i v a t e                  *
  113. *                                                                           *
  114. *   Stores mouse position when screen saver starts.                         *
  115. *                                                                           *
  116. *   OUTPUT: LastMouse = mouse position                                      *
  117. *                                                                           *
  118. ****************************************************************************}
  119.  
  120. procedure TScSaverWin.WMActivate    (var Msg: TMessage);
  121. begin
  122. if (Msg.wParam <> 0) then               { are we going to be activated? }
  123.      GetCursorPos (LastMouse);          { then get mouse position }
  124. DefWndProc (Msg);
  125. end;
  126.  
  127. {****************************************************************************
  128. *                                                                           *
  129. *           T S c S a v e r W i n . W M M o u s e M o v e                   *
  130. *                                                                           *
  131. *   Checks if mouse has been moved to a new position. If so, calls STOP.    *
  132. *                                                                           *
  133. *   INPUT: LastMouse = mouse position on last saver activation              *
  134. *                                                                           *
  135. ****************************************************************************}
  136.  
  137. procedure TScSaverWin.WMMouseMove (var Msg: TMessage);
  138.  
  139. var  CurrMouse: Tpoint;
  140.  
  141. begin
  142. SetCursor (0);                             { Hide cursor again }
  143. GetCursorPos (CurrMouse);                  { Where's the mouse?  }
  144.  
  145. { Most screen savers I examined used a to -1 initialized variable for LastMouse
  146.   and contained the following test on -1. I don't see the reason why. If some-
  147.   body does, he or she should a) remove the braces around the test and b) ex-
  148.   plain this to me so that I don't have to die stupid. }
  149. { if (LastMouse.x = -1) then
  150.       GetCursorPos (LastMouse)
  151.     else  }
  152.  
  153. if (LastMouse.x <> CurrMouse.x) or (LastMouse.y <> CurrMouse.y) then
  154.      Stop (Msg);            { call Stop in case of new mouse position }
  155.  
  156. DefWndProc (Msg);
  157. end;
  158.  
  159. {****************************************************************************
  160. *                                                                           *
  161. *           T S c S a v e r W i n . W M x b u t t o n d o w n,              *
  162. *                               - . W M x K e y d o w n                     *
  163. *                                                                           *
  164. *   Frontends that just call Stop on any key event.                         *
  165. *                                                                           *
  166. *   NOTE: How about Borland to add dynamic methods with multiple indices?   *
  167. *                                                                           *
  168. ****************************************************************************}
  169.  
  170. procedure TScSaverWin.WMLbuttondown (var Msg: TMessage);
  171. begin Stop (Msg); end;
  172.  
  173. procedure TScSaverWin.WMRbuttondown (var Msg: TMessage);
  174. begin Stop (Msg); end;
  175.  
  176. procedure TScSaverWin.WMMbuttondown (var Msg: TMessage);
  177. begin Stop (Msg); end;
  178.  
  179. procedure TScSaverWin.WMSyskeydown  (var Msg: TMessage);
  180. begin Stop (Msg); end;
  181.  
  182. procedure TScSaverWin.WMKeydown     (var Msg: TMessage);
  183. begin Stop (Msg); end;
  184.  
  185. {****************************************************************************
  186. *                                                                           *
  187. *                   T S c S a v e r W i n . S t o p                         *
  188. *                                                                           *
  189. *   Closes the screen saver window if the PasswordOK function from unit     *
  190. *   SsavePwd says that it's ok to do do.                                    *
  191. *                                                                           *
  192. ****************************************************************************}
  193.  
  194. procedure TScSaverWin.Stop (var Msg: TMessage);
  195. begin
  196. if PasswordOK (@Self) then
  197.     PostMessage (HWindow, WM_CLOSE, 0, 0);
  198. DefWndProc (Msg);
  199. end;
  200.  
  201. {****************************************************************************
  202. *                                                                           *
  203. *                T S c S a v e r W i n . D o T h e S h o w                  *
  204. *                                                                           *
  205. *   Animates the screen - well, at least its descendants should...          *
  206. *                                                                           *
  207. ****************************************************************************}
  208.  
  209. procedure TScSaverWin.DoTheShow;
  210. begin
  211. end;
  212.  
  213.  
  214. begin
  215. end.
  216.  
  217.